package com.saas.tenant.config;

import com.saas.tenant.interceptor.TenantInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final TenantInterceptor tenantInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tenantInterceptor)
                .addPathPatterns("/**")          // 拦截所有
                .excludePathPatterns(            // 放行列表
                        "/api/tenant/register",
                        "/api/tenant/login",
                        "/error",
                        "/swagger-ui/**",
                        "/v3/api-docs/**");
    }
}